<% layout('/layouts/default.html', {title: '举报悬赏管理', libs: ['dataGrid']}){ %>
<div class="main-content">
	<div class="box box-main">
		<div class="box-header">
			<div class="box-title">
				<i class="fa icon-notebook"></i> ${text('举报悬赏管理')}
			</div>
			<div class="box-tools pull-right">
				<a href="#" class="btn btn-default" id="btnSearch" title="${text('查询')}"><i class="fa fa-filter"></i> ${text('查询')}</a>
				<% if(hasPermi('tk:tkJubao:edit')){ %>
					<a href="${ctx}/tk/tkJubao/form" class="btn btn-default btnTool" title="${text('新增举报悬赏')}"><i class="fa fa-plus"></i> ${text('新增')}</a>
				<% } %>
				<a href="#" class="btn btn-default" id="btnSetting" title="${text('设置')}"><i class="fa fa-navicon"></i></a>
			</div>
		</div>
		<div class="box-body">
			<#form:form id="searchForm" model="${tkJubao}" action="${ctx}/tk/tkJubao/listData" method="post" class="form-inline hide"
					data-page-no="${parameter.pageNo}" data-page-size="${parameter.pageSize}" data-order-by="${parameter.orderBy}">
				<div class="form-group">
					<label class="control-label">${text('用户id')}：</label>
					<div class="control-inline">
						<#form:input path="userId" maxlength="50" class="form-control width-120"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('内容')}：</label>
					<div class="control-inline">
						<#form:input path="content" maxlength="255" class="form-control width-120"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('图片集合')}：</label>
					<div class="control-inline">
						<#form:input path="pics" class="form-control width-120"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('create_time')}：</label>
					<div class="control-inline">
						<#form:input path="createTime" readonly="true" maxlength="20" class="form-control laydate width-datetime"
							dataFormat="datetime" data-type="datetime" data-format="yyyy-MM-dd HH:mm"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('任务ID')}：</label>
					<div class="control-inline">
						<#form:input path="taskId" maxlength="50" class="form-control width-120"/>
					</div>
				</div>
				<div class="form-group">
					<button type="submit" class="btn btn-primary btn-sm">${text('查询')}</button>
					<button type="reset" class="btn btn-default btn-sm isQuick">${text('重置')}</button>
				</div>
			</#form:form>
			<table id="dataGrid"></table>
			<div id="dataGridPage"></div>
		</div>
	</div>
</div>
<% } %>

<script id="shenheTask" type="text/template">
	<form id="inputForm" action="${ctx}/tk/tkTask/save" method="post" enctype="multipart/form-data"
		  class="form-horizontal mt20 mb10" style="overflow:auto;max-height:200px;">
		<div class="row">
			<div class="col-xs-12 col-xs-offset-1">
				<input type="hidden" id="id" name="id" class="form-file"/>
				<input type="hidden" id="taskStatus" name="taskStatus" class="form-file"/>
				<label class="control-label col-sm-1" title="">
					<span class="required hide">*</span> <i class="fa icon-question hide"></i></label>
				<div class="col-sm-10">
					<#form:textarea name="failExplain" rows="4" placeholder="下架原因" maxlength="100"  class="form-control"/>
				</div>
			</div>
		</div>
	</form>
</script>
<script>
// 初始化DataGrid对象
$('#dataGrid').dataGrid({
	searchForm: $("#searchForm"),
	columnModel: [
		{header:'${text("举报人手机号")}', name:'icUser.mobile', index:'a.user_id', width:150, align:"left"},
		{header:'${text("内容")}', name:'content', index:'a.content', width:150, align:"left"},
		{header:'${text("图片集合")}', name:'pics', index:'a.pics', width:150, align:"left", formatter: function(val, obj, row, act){
			var arr = JSON.parse(val);
			var html = "";
			console.log(arr);
			for (let i = 0; i < arr.length; i++) {
				let arrElement = arr[i];
				html+='<img src="'+arrElement+'" width="50" height="50" style="margin-left: 5px"/>';
			}
			console.log(html);
			return html;
		}},
		{header:'${text("时间")}', name:'createTime', index:'a.create_time', width:150, align:"center"},
		{header:'${text("任务")}', name:'tkTask.title', index:'a.task_id', width:150, align:"left", formatter: function(val, obj, row, act){
			return '<a href="${ctx}/tk/tkTask/taskInfo?id='+row.taskId+'" class="btnList">'+val+'</a>';
		}},
		{header:'${text("操作")}', name:'actions', width:120, formatter: function(val, obj, row, act){
				var actions = [];
				actions.push('<a href="javascript:;" onclick="xiajia(\''+row.taskId+'\')" class="" title="${text("审核")}">违规下架</a>&nbsp;');

			return actions.join('');
		}}
	],
	// 加载成功后执行事件
	ajaxSuccess: function(data){
		
	}
});

function xiajia(id){
	js.layer.open({
		type: 1,
		area: ['600px'],
		title: '${text("任务下架")}',
		resize: false,
		scrollbar: true,
		content: js.template('shenheTask'),
		success: function(layero, index){
			layero.find('#id').val(id);
		},
		btn: ['<i class="fa fa-check"></i> ${text("违规下架")}',
			'<i class="fa fa-close"></i> ${text("关闭")}'],
		btn1: function(index, layero){
			layero.find('#taskStatus').val("4");
			var form = {
				inputForm: layero.find('#inputForm'),
			};
			js.ajaxSubmitForm(form.inputForm, function(data){
				if(data.result == Global.TRUE){
					js.showMessage("下架成功");
					layero.find('#failExplain').val("");
					page();
					js.layer.closeAll();
				}else{
					js.showErrorMessage(data.message);
				}
			}, "json");
			return false;
		},
	})
}
</script>